package com.youngwang.lambda;


import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * @author youngwang
 *         Date: 2016/8/31
 */
public class LambdaAndPredicate {
    public static void main(String[] args) {
        List<String> languages = Arrays.asList("Java", "Scala", "C++", "Haskell", "Lisp");
        if (!CollectionUtils.isEmpty(languages)) {
            Predicate<String> startWithJ = (n) -> n.startsWith("J");
            Predicate<String> fourLetterLong = (n) -> n.length() == 4;
            languages.stream().filter(startWithJ.or(fourLetterLong)).forEach((n) ->
                    System.out.print("\nName, which starts with 'J' or four letter long is : " + n));
        }
    }
}
